Miraç Lütfullah Gülgönül


Raspberry Pi Headless Setup

25 June 2019

This post is about how to setup your Raspberry Pi in a headless configuration, so you can plug it in to your main computer and SSH into it. I will be using macOS Mojave 10.14.4 and a Raspberry Pi Zero W, but most of this should work on any *nix system and any relatively new Raspberry Pi.

Installing the OS

You will first download the image file for Raspbian, and then burn it into an SD card (minimum of 8 GB should be fine) which your Raspberry Pi will boot from.

Here is the download page for Raspbian OS, since this is a headless setup, you will install the Lite version: which is lightweight and does not have a desktop included. After downloading the .zip file, extract it to a .img and burn this disk image to the SD card using balenaEtcher. You can use dd if you want, but I have found Etcher to be faster and more reliable.

Enabling SSH and Internet Sharing

After the burning process is complete, take out the SD card and plug it again. You will see a partition named boot show up: we are going to edit some files here to enable SSH and the ability to share your computer’s internet connection with the Raspberry Pi.

On a terminal, cd into this partition.

Now on your Macbook, go to System Preferences > Sharing, enable the tick of Internet Sharing. When you connect your Pi, check the tick on RNDIS/Ethernet Gadget. It should look something like this:

Enabling SSH Root Login

Now that we have enabled SSH, you can plug in the SD card to your Raspberry Pi, and connect it via USB. You can then SSH into it by ssh pi@raspberrypi.local with password raspberry. Once you are logged in you can:

After this, reboot the machine by sudo reboot. Give it a few seconds to boot-up, and then SSH into the root user by ssh root@raspberrypi.local, entering the password you had set.

Creating New User

Now that you have root access, you can add/remove users easily.

Changing Device Name

The default device name is raspberrypi, which can cause confusion if there are multiple Pi’s at play. To change this, (preferably while still logged in to the root user):

Enabling SSH Login Without Password

Since you will presumably be SSH’ing into your Pi from the same computer all the time, it becomes cumbersome after a while to enter the password. To go around this, we will create a public/private RSA keypair which will allow us to authenticate our computer to the Pi without entering the password each time.

Now, you can SSH into the Pi from your computer anytime without entering the user passwords.

\space